package com.example.springboot_sp.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.springboot_sp.common.Result;
import com.example.springboot_sp.entity.Files;
import com.example.springboot_sp.entity.User;
import com.example.springboot_sp.entity.Word;
import com.example.springboot_sp.service.IUserService;
import com.example.springboot_sp.service.IWordService;
import com.example.springboot_sp.service.IFileService;
import com.example.springboot_sp.service.impl.FileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/echarts")
public class EchartsController {

    @Autowired
    private IUserService userService;

    @Autowired
    private IWordService wordService;

    @Autowired
    private IFileService fileService;

    @GetMapping("/example")
    public Result get() {
        Map<String, Object> map = new HashMap<>();
        map.put("x", CollUtil.newArrayList("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"));
        map.put("y", CollUtil.newArrayList(150, 230, 224, 218, 135, 147, 260));
        return Result.success(map);
    }

    @GetMapping("/members")
    public Result members() {
        //用户注册季度
        List<User> list = userService.list();
        int u1 = 0; // 第一季度
        int u2 = 0; // 第二季度
        int u3 = 0; // 第三季度
        int u4 = 0; // 第四季度
        int userTotal =0;//总数
        for (User user : list) {
            Date createTime = user.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter) {
                case Q1: u1 += 1; break;
                case Q2: u2 += 1; break;
                case Q3: u3 += 1; break;
                case Q4: u4 += 1; break;
                default: break;
            }
            userTotal=u1+u2+u3+u4;
        }
        //单词注册季度
        List<Word> list1 = wordService.list();
        int w1 = 0; // 第一季度
        int w2 = 0; // 第二季度
        int w3 = 0; // 第三季度
        int w4 = 0; // 第四季度
        for (Word word : list1) {
            Date createTime = word.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter) {
                case Q1: w1 += 1; break;
                case Q2: w2 += 1; break;
                case Q3: w3 += 1; break;
                case Q4: w4 += 1; break;
                default: break;
            }
        }
        //文件注册季度
        List<Files> filelist = fileService.list();
        int f1 = 0; // 第一季度
        int f2 = 0; // 第二季度
        int f3 = 0; // 第三季度
        int f4 = 0; // 第四季度
        int filesTotal=0;
        for (Files files : filelist) {
            Date createTime = files.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter) {
                case Q1: f1 += 1; break;
                case Q2: f2 += 1; break;
                case Q3: f3 += 1; break;
                case Q4: f4 += 1; break;
                default: break;
            }
            filesTotal=f1+f2+f3+f4;
        }
        //单词词性
        List<Word> lists = wordService.list();
        int n=0;
        int v=0;
        int adj=0;
        int adv=0;
        int j=0;
        int wordTotal =0;//总数
        for (Word word : lists) {
            String part = word.getPart();
            switch (part) {
                case "n(名词)": n += 1; break;
                case "V(动词)": v += 1; break;
                case "adj(形容词)": adj += 1; break;
                case "adv(副词)": adv += 1; break;
                case "介词": j += 1; break;
                default: break;
            }
            wordTotal=n+v+adj+adv+j;
        }
        //单词类别
        List<Word> partList =wordService.list();
        int gride_must = 0;
        int gride_base = 0;
        int gride_senior = 0;
        int gride_ct4 = 0;
        int gride_ct6 = 0;
        int gride_over = 0;
        for (Word word : partList){
            String gride = word.getGride();
            switch (gride){
                case "必考词": gride_must+=1; break;
                case "基础词": gride_base+=1; break;
                case "高中词汇": gride_senior+=1; break;
                case "四级词汇": gride_ct4+=1; break;
                case "六级词汇": gride_ct6+=1; break;
                case "超纲词汇": gride_over+=1; break;
                default: break;
            }

        }
        //文件类型
        List<Files> filesTypeLists = fileService.list();
        int png=0;
        int jpg=0;
        int pdf=0;
        int ppt=0;
        int doc=0;
        int xls=0;
        for (Files files : filesTypeLists) {
            String filesType = files.getType();
            switch (filesType) {
                case "jpg": jpg += 1; break;
                case "png": png += 1; break;
                case "pdf": pdf += 1; break;
                case "ppt": ppt += 1; break;
                case "pptx": ppt += 1; break;
                case "doc": doc += 1; break;
                case "docx": doc += 1; break;
                case "xls": xls += 1; break;
                case "xlsx": xls += 1; break;
                default: break;
            }
        }

        return Result.success(CollUtil.newArrayList(u1, u2, u3, u4,userTotal,n,v,adj,adv,j,wordTotal,w1,w2,w3,w4,f1,f2,f3,f4,filesTotal,png,jpg,pdf,ppt,doc,xls,gride_must,gride_base,gride_senior,gride_ct4,gride_ct6,gride_over));
    }

}